package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sg.hms.Model.User;
import com.sg.hms.Service.UserService;
import com.sg.hms.ServiceImpl.UserServiceImpl;
/**
 * 
 * @author 陈良机
 *
 */
public class UpswUpController extends HttpServlet{
	UserService uservice=new UserServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int flag=0;
		PrintWriter pw=resp.getWriter();
		User u=(User) req.getSession().getAttribute("currentuser");
		int elId=u.getuId();
		String oldpsw=req.getParameter("oldpsw");
		String newpsw=req.getParameter("newpsw");
		if(oldpsw.equals(u.getUpsw())){
			flag=uservice.upPsw(newpsw, elId);
			u.setUpsw(newpsw);//修改密码后，设置当前用户的当前密码为修改的新密码
			pw.write(String.valueOf(flag));
		}else{
			pw.write(String.valueOf(flag));
		}
		pw.flush();
		pw.close();
	} 
}
